<?php
declare (strict_types = 1);

namespace app\common\model;
use think\Exception;
use think\Model;

/**
 * @mixin \think\Model
 */
class Invoice extends Model
{

    public static function onAfterInsert($model) {
        $order = Order::findOrEmpty($model->order_id);
        if ($order->isEmpty()) {
            throw new Exception("未找到相关订单");
        }
        $order->invoice_status = PublicStatus::PUBLIC_STATUS_TWO;
        $order->invoice_id = $model->id;
        $order->save();
     }




    //

    public function order(){
        return $this->belongsTo(Order::class,'order_id');
    }

    public function user(){
        return $this->belongsTo(User::class,'user_id');
    }

}
